基于frida的so函数hook实战 |
您所在的位置:网站首页 › frida hook 脚本 › 基于frida的so函数hook实战 |
一、环境
win10、python38、frida库、夜神模拟器 (1)安装frida环境 (a)frida python -m pip install frida //运行python38版本 //python -m module_name相当于python /path/to/module.py(当我们知道一个模块的名字,但不知道它的路径时,我们可以通过 -m 参数)假如以上方法出错,建议本地下载frida包安装 https://pypi.org/project/frida/#files(选择frida-14.2.8-py3.8-win-amd64.egg),然后执行python -m easy_install xxx.egg,其中,easy_install需要安装setuptools库,且版本有要求,为pip install "setuptools==45.2.0"。 (b) frida-tools python -m pip install frida-tools 在win10终端执行frida-ps -U,显示进程表示成功 在https://github.com/frida/frida/releases中下载frida-server-14.2.8-android-x86.xz(通过adb shell getprop ro.product.cpu.abi查看相应版本),解压后将文件frida-server-14.2.8-android-x86放在夜神模拟器的/data/local/tmp目录,并且赋予权限,基于root执行./frida-server-14.2.8-android-x86 二、so源码实例 #include #include #include"test.h" jstring JNICALL Java_com_example_mi_demoso_JNITest_getStringFromJNI(JNIEnv* env, jobject jo) { char str[] = "x HelloWorld from JNI12345!"; int c = test_add(97,1); str[0] = (char)c; return (*env)->NewStringUTF(env, str); } int test_add(int a,int b){ return a+b; }这里将对test_add函数进行hook 三、寻找要hook函数的偏移地址将要hook的so(libjnitest.so)拖进ida 注意: 返回字符串时,在retval.replace(100); //替换返回值为100之后需要: var env = Java.vm.getEnv(); //获取env对象,即第一个参数 var jstrings = env.newStringUtf("xxxx"); //返回的是字符串指针,构造一个newStringUtf对象用来代替这个指针 retval.replace(jstrings); //替换返回值 五、效果验证启动frida-server后进行,启动端口转发 adb forward tcp:27043 tcp:27043和adb forward tcp:27042 tcp:27042 然后执行python脚本(frida脚本),接着启动应用:
参考: https://www.cnblogs.com/aWxvdmVseXc0/p/12463319.html https://refate.github.io/2019/01/13/rida_install/ |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |